/*
 * PerformanceController
 *
 * Copyright (c) 2018 Manulife International Ltd.
 *
 * Description: Initial data for mandatory fields
 *
 * Maintenance History
 *
 * YYMMDD  Who              Reason
 * ======= ================ ====================================================
 * 180411  Cherry Xu        Application development
 */
package com.manulife.hk.performance.datamodel;

import java.math.BigDecimal;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;

import com.manulife.hk.performance.model.SubmitSale;
import com.manulife.hk.performance.model.ValidateList;

@Component
public class SubmitSalesDataModel {
	
	/**
	 * @param submitSale
	 * @description Initial data for mandatory Fields
	 * @return submitSale
	 */

	public ValidateList<SubmitSale> initialDataForMandatoryFields(ValidateList<SubmitSale> submitSales, String submitSalesKey) {
		int count = 1;
		for(SubmitSale submitSale: submitSales){
			if(StringUtils.isEmpty(submitSale.getSubmitSalesKey())) {
				submitSale.setSubmitSalesKey(submitSalesKey);
			}
			if(StringUtils.isEmpty(submitSale.getSubmitSalesSubKey())) {
				submitSale.setSubmitSalesSubKey(String.valueOf(count++));
			}
			if(StringUtils.isEmpty(submitSale.getSubmitPc())) {
				submitSale.setSubmitPc(new BigDecimal(0));
			}
			if(StringUtils.isEmpty(submitSale.getSubmitApe())) {
				submitSale.setSubmitApe(new BigDecimal(0));
			}
			if(StringUtils.isEmpty(submitSale.getSubmitCaseCount())) {
				submitSale.setSubmitCaseCount(new BigDecimal(0));
			}
        }
		
		return submitSales;
	}


	/**
	 * @param 
	 * @description Get the date time for app in key
	 * @return current date yyyy-MM-dd-HH.mm.ss.SSS
	 */
	private String getCurrentDateTime() {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd-HH.mm.ss.SSS");
	    Timestamp nowdate = new Timestamp(System.currentTimeMillis());
	    return sdf.format(nowdate);
	    
	}


	/**
	 * @param 
	 * @description Get the random 6-digits
	 * @return 
	 */
	public String generateRandom() {
		return String.valueOf((int)((Math.random()*9+1)*10000000));
	}
	
	/**
	 * @param 
	 * @description Get the current date for submit sales key
	 * @return yyyyMMdd
	 */
	public String getCurrentDate() {
		Date d = new Date();
		SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
		return sdf.format(d);
	}


}
